package com.example.permissionsystem1_1.businessFunction.controller.converter;

import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.departmentUserReqDto.DepartmentUserSelectAllDepartmentsByUserIdReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.departmentUserReqDto.DepartmentUserSetDepartmentUserRelationReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentUserRspDto.DepartmentUserRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentUserRspDto.DepartmentUserSelectAllDepartmentsByUserIdRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentUserRspDto.DepartmentUserSetDepartmentUserRelationRspDto;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSelectAllDepartmentsByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSetDepartmentUserRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSelectAllDepartmentsByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSetDepartmentUserRelationRspModel;
import com.example.permissionsystem1_1.common.businessFunction.BaseControllerConverter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class DepartmentUserControllerConverter extends BaseControllerConverter {
    //1.根据用户id查询全部部门信息
    public static DepartmentUserSelectAllDepartmentsByUserIdReqModel convertDtoToModel(DepartmentUserSelectAllDepartmentsByUserIdReqDto reqDto) {
        if(reqDto==null || reqDto.getUserId()==null){
            return null;
        }
        DepartmentUserSelectAllDepartmentsByUserIdReqModel reqModel=new DepartmentUserSelectAllDepartmentsByUserIdReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static DepartmentUserSelectAllDepartmentsByUserIdRspDto convertModelToDto(DepartmentUserSelectAllDepartmentsByUserIdRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        DepartmentUserSelectAllDepartmentsByUserIdRspDto rspDto=new DepartmentUserSelectAllDepartmentsByUserIdRspDto();
        if(rspModel.getDepartmentUserRspModels()!=null&&rspModel.getDepartmentUserRspModels().size()>0){
            List<DepartmentUserRspDto> departmentUserRspDtos=new ArrayList<>();
            List<DepartmentUserRspModel> departmentUserRspModels=rspModel.getDepartmentUserRspModels();
            for (DepartmentUserRspModel departmentUserRspModel:departmentUserRspModels) {
                DepartmentUserRspDto departmentUserRspDto=new DepartmentUserRspDto();
                BeanUtils.copyProperties(departmentUserRspModel, departmentUserRspDto);
                departmentUserRspDtos.add(departmentUserRspDto);
            }
            rspDto.setDepartmentUserRspDtos(departmentUserRspDtos);
        }
        return rspDto;
    }
    //2.设置部门与用户的关联关系
    public static DepartmentUserSetDepartmentUserRelationReqModel convertDtoToModel(DepartmentUserSetDepartmentUserRelationReqDto reqDto) {
        if(reqDto==null || reqDto.getUserId()==null || reqDto.getDepartmentId()==null){
            return null;
        }
        DepartmentUserSetDepartmentUserRelationReqModel reqModel=new DepartmentUserSetDepartmentUserRelationReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static DepartmentUserSetDepartmentUserRelationRspDto convertModelToDto(DepartmentUserSetDepartmentUserRelationRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        DepartmentUserSetDepartmentUserRelationRspDto rspDto=new DepartmentUserSetDepartmentUserRelationRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }


}
